package com.zengqingfa.designpattern.create.prototype.deep;

/**
 *
 * @fileName: Client
 * @author: zengqf3
 * @date: 2021-4-23 17:35
 * @description:
 */
public class Client {

    public static void main(String[] args) throws Exception {
        Owner owner = new Owner("aa");
        Shape shape = new Shape("bb", owner);
        Shape clone = (Shape) shape.clone();

        //方式一：使用  clone.owner = (Owner) clone.getOwner().clone();
        /**
         * shape=Shape{name='bb', owner=Owner{name='cc'}com.zengqingfa.designpattern.create.prototype.deep.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.deep.Shape@6f496d9f
         * clone=Shape{name='bb', owner=Owner{name='aa'}com.zengqingfa.designpattern.create.prototype.deep.Owner@723279cf}com.zengqingfa.designpattern.create.prototype.deep.Shape@10f87f48
         */
        owner.setName("cc");
        System.out.println("shape=" + shape);
        System.out.println("clone=" + clone);

        //方式二：使用序列化的方式
        /**
         * shape=Shape{name='bb', owner=Owner{name='cc'}com.zengqingfa.designpattern.create.prototype.deep.Owner@5b480cf9}com.zengqingfa.designpattern.create.prototype.deep.Shape@6f496d9f
         * deepClone=Shape{name='bb', owner=Owner{name='cc'}com.zengqingfa.designpattern.create.prototype.deep.Owner@4459eb14}com.zengqingfa.designpattern.create.prototype.deep.Shape@5a2e4553
         */
        Shape deepClone = (Shape) shape.deepClone();
        System.out.println("shape=" + shape);
        System.out.println("deepClone=" + deepClone);
    }
}
